package com.xiaoyi.springboot.config;

import org.springframework.http.HttpStatus;

/**
 *
 * @author xiaoyi
 * @date 2021/10/9 14:26
 * @version v1.0
 */
public class ResponseHelper {

    public ResponseHelper() {
    }
    /*
     *  404
     * @author xiaoyi
     * @date 2021/10/10 20:13
     * @param null
     * @return
     * @version v1.0
     */
    public static <T>ResponseModel<T> notFound(String message) {
       ResponseModel response = new ResponseModel();
        response.setStatus(HttpStatus.NOT_FOUND.value());
        response.setCode(HttpStatus.NOT_FOUND.getReasonPhrase());
        response.setMessage(message);
        return response;
    }
    /*
     *  500
     * @author xiaoyi
     * @date 2021/10/10 20:13
     * @param null
     * @return
     * @version v1.0
     */
    public static <T>ResponseModel<T> internalServerError(String message) {
       ResponseModel response = new ResponseModel();
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setCode(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
        response.setMessage(message);
        return response;
    }
    /*
     * 400
     * @author xiaoyi
     * @date 2021/10/10 20:13
     * @param null
     * @return
     * @version v1.0
     */
    public static <T>ResponseModel<T> validationFailure(String message) {
       ResponseModel response = new ResponseModel();
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        response.setCode(HttpStatus.BAD_REQUEST.getReasonPhrase());
        response.setMessage(message);
        return response;
    }
    /*
     *  200
     * @author xiaoyi
     * @date 2021/10/10 20:13
     * @param null
     * @return
     * @version v1.0
     */
    public static <T>ResponseModel<T> buildResponseModel(T result) {
        ResponseModel response = new ResponseModel();
        response.setStatus(HttpStatus.OK.value());
        response.setCode(HttpStatus.OK.getReasonPhrase());
        response.setMessage(HttpStatus.OK.getReasonPhrase());
        response.setResult(result);
        return response;
    }


}
